<?php

namespace app\modules\Product\models;

use Yii;

/**
 * This is the model class for table "invoice_detail".
 *
 * @property int $id
 * @property int $invoice_id invoice ID
 * @property int $num 数量
 * @property string $s_price 单价金额
 * @property string $t_price 总金额
 * @property string $remark 备注
 * @property int $user_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at
 */
class InvoiceDetail extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'invoice_detail';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['invoice_id', 'num', 'user_id'], 'integer'],
            [['s_price', 't_price'], 'number','min'=>0],
            [['s_price','num'], 'required'],
            [['created_at', 'updated_at'], 'safe'],
            [['remark'], 'string', 'max' => 1024],
        ];
    }

     //保存前处理
    public function beforeSave($insert) {//{{{

        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);

    }//}}}

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'invoice_id' => Yii::t('app.product', 'Invoice ID'),
            'num' => Yii::t('app.product', 'Invoice Num'),
            's_price' => Yii::t('app.product', 'S Price'),
            't_price' => Yii::t('app.product', 'T Price'),
            'remark' => Yii::t('app.product', 'Remark'),
            'user_id' => Yii::t('app', 'User ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }
}
